#include "common.h"

int subarraySum(vector<int>& nums, int k)
{
	int n = nums.size();
	vector<int> sum(n + 1, 0);
	for (int i = 0; i < n; i++)
	{
		sum[i + 1] = sum[i] + nums[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if (sum[j] - sum[i] == k) ans++;
		}
	}
	return ans;
}